﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Net.Http;
using System.Net.Http.Headers;
using TPLOAWebClient.Resources;
using System.Web.Security;
namespace TPLOAWebClient
{
    public partial class staffview : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                HttpClient client = (HttpClient)Session["httpclient"];
                HttpResponseMessage response = null;

                if (Session["username"] != null)
                {
                    response = client.GetAsync("api/members/" + Session["username"]).Result;
                    var member = response.Content.ReadAsAsync<Member>().Result;
                    if (member.UserType.Equals("Student"))
                    {
                        Response.Redirect("studentprofile.aspx");
                    }
                    else if (member.UserType.Equals("Clinic"))
                    {
                        Response.Redirect("clinicprofile.aspx");
                    }
                    else if (member.UserType.Equals("Admin"))
                    {
                        Response.Redirect("adminprofile.aspx");
                    }

                    response = client.GetAsync("api/Staffs/" + Session["username"]).Result;
                    var staff = response.Content.ReadAsAsync<Staff>().Result;
                    if (!staff.ApprovePermissions)
                    {
                        Response.Redirect("staffprofile.aspx");
                    }
                }

                string loaid = Request.QueryString["details"];
                response = client.GetAsync("api/LOAs/" + loaid).Result;  // Blocking call!
                if (response.IsSuccessStatusCode)
                {
                    // Parse the response body. Blocking!
                    var loa = response.Content.ReadAsAsync<LOA>().Result;
                    adminnoLbl.Text = loa.StudentAdminNo;
                    loaidLbl.Text = Convert.ToString(loa.LOAID);
                    datesubmitLbl.Text = loa.SubmitDateTime;
                    datefromLbl.Text = loa.StartDateTime;
                    datetoLbl.Text = loa.EndDateTime;
                    reasonLbl.Text = loa.LOAReason;
                    if (loa.GradedAssignmentClash == true)
                    {
                        gradedassignmentLbl.Text = "Yes";
                    }
                    else
                    {
                        gradedassignmentLbl.Text = "No";
                    }
                    gradedassignmentdetailsLbl.Text = loa.GradedAssignmentClashDetails;
                    statusLbl.Text = loa.ReviewStatus;
                    rejectreasonLbl.Text = loa.RejectReason;
                    mcidLbl.Text = Convert.ToString(loa.MCID);
                }
                else
                {
                    retrieveLbl.Text += response.StatusCode + "(" + response.ReasonPhrase + ")";
                }
            
        }

        protected void modifyBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("staffmodify.aspx?details=" + loaidLbl.Text);
        }

        protected void profileBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("staffprofile.aspx");
        }

        protected void viewloaBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("staffviewloa.aspx");
        }

        protected void submitloaBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("staffsubmitloa.aspx");
        }

        protected void faqBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("stafffaq.aspx");
        }

        protected void otherservicesBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("staffotherservice.aspx");
        }

        protected void LogoutBtn_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            FormsAuthentication.SignOut();
            Response.Redirect("default.aspx");
        }
    }
}